package Thread;
import java.util.concurrent.Semaphore;
/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-11-15
 * Time：09:37
 */
public class SemaphoreDemo {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(3);
        //P操作
        semaphore.acquire();
        System.out.println("申请资源");
        semaphore.acquire();
        System.out.println("申请资源");
        semaphore.acquire();
        System.out.println("申请资源");
        semaphore.acquire();
        System.out.println("申请资源");
        //V操作
        semaphore.release();
    }
}
